package com.zhisheng.gufei.city.entity;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name = "GF_CITY")
public class City {
	
	@Id
	@GeneratedValue
	private int id;
	
	private String cityName;
    
	@ManyToOne(fetch = FetchType.LAZY)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	@JoinColumn(name="parent")
	private City parent;
	
	@OneToMany(fetch = FetchType.LAZY , mappedBy = "parent")
	@Cascade(value = CascadeType.SAVE_UPDATE)
	@OrderBy(value = "id")
	private Set<City> subs;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	public City getParent() {
		return parent;
	}

	public void setParent(City parent) {
		this.parent = parent;
	}

	public Set<City> getSubs() {
		return subs;
	}

	public void setSubs(Set<City> subs) {
		this.subs = subs;
	}

    
}
